package com.splant.android.smart.UILevel;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.TextView;

import com.splant.android.R;

/**
 * Created by Administrator on 2016/7/7.
 */
public class System_Selector_Activity extends Activity implements View.OnClickListener {

    private Button enterBtn;
    private SeekBar progresss;
    private TextView curValueTv;
    private TextView selectionRangeTv;
    private ImageButton reduceBtn;
    private ImageButton addBtn;
    private int typeId;
    private int tagId;
    private int curValue;
    private int minValue;
    private Class cls;
    private FrameLayout fl_cancel;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.system_selector);
        enterBtn = (Button) findViewById(R.id.enterBtn);
        progresss = (SeekBar) findViewById(R.id.progresss);
        curValueTv = (TextView) findViewById(R.id.curValueTv);
        selectionRangeTv = (TextView) findViewById(R.id.selectionRangeTv);
        reduceBtn = (ImageButton) findViewById(R.id.reduceBtn);
        addBtn = (ImageButton) findViewById(R.id.addBtn);
        fl_cancel = (FrameLayout) findViewById(R.id.fl_cancel);

        Intent intent = getIntent();
        cls = intent.getClass();
        typeId = intent.getIntExtra("TypeId", 0);
        tagId = intent.getIntExtra("TagId", 0);
        curValue = intent.getIntExtra("CurValue", 0);
        minValue = intent.getIntExtra("MinValue", 1);
        final int maxValue = intent.getIntExtra("MaxValue", 100);

        selectionRangeTv.setText("Area：" + String.valueOf(minValue) + "-" + String.valueOf(maxValue));

        progresss.setMax(maxValue - minValue);

        progresss.setProgress(curValue - minValue);
        curValueTv.setText(String.valueOf(curValue));

        reduceBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (curValue > minValue) {
                    curValue -= 1;
                    progresss.setProgress(curValue - minValue);
                    curValueTv.setText(String.valueOf(curValue));
                }
            }
        });
        addBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (curValue < maxValue) {
                    curValue += 1;
                    progresss.setProgress(curValue - minValue);
                    curValueTv.setText(String.valueOf(curValue));
                }
            }
        });
        enterBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1 = new Intent(System_Selector_Activity.this, cls);
                intent1.putExtra("TypeId", typeId);
                intent1.putExtra("TagId", tagId);
                intent1.putExtra("CurValue", curValue);
                setResult(RESULT_OK, intent1);
                finish();
            }
        });
        progresss.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                curValue = minValue + i;
                curValueTv.setText(String.valueOf(curValue));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
            }
        });
        fl_cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fl_cancel:
                finish();
                break;
        }
    }
}
